﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cogency.languages
{
    public class Indent
    {
        private int Level;
        private const string Spaces = "    ";
        private string IndentString;
        
        public Indent()
        {
            IndentString = "";
            Level = 0;
        }

        private void RebuildIndentString()
        {
            StringBuilder temp = new StringBuilder();
            for (int i = 0; i < Level; ++i  )
            {
                temp.Append(Spaces);
            }
            IndentString = temp.ToString();
        }

        public static Indent operator --(Indent instance)
        {
            instance.Level--;
            if (instance.Level < 0)
                instance.Level = 0;
            instance.RebuildIndentString();
            return instance;
        }

        public static Indent operator++(Indent instance)
        {
            instance.Level++;
            instance.RebuildIndentString();
            return instance;
        }

        public override string ToString()
        {
            return IndentString;
        }
    }
}
